/**
 * App主控件的入口
 */
import xs, { Stream } from 'xstream';
import { VNode } from '@cycle/dom';
import isolate from '@cycle/isolate';
import { Sources, Sinks, AppSources, AppSinks, AppReducer, TodoListSources, TodoListSinks } from '../types';
//import intent from './intent';
import view from './view';
import TodoList from '../Todo';

/**
 * 返回App的组件
 * @param sources 
 */
export default function App(sources : AppSources) : AppSinks
{
    // 获取TodoList的Sinks
    const todoListSinks : TodoListSinks = isolate(TodoList, 'TodoList')(sources);
    // 在这里渲染TodoList的Dom
    // const action$ : Stream<AppReducer> = intent(sources.DOM);
    const vdom$ : Stream<VNode> = view(sources.onion.state$, todoListSinks.DOM as Stream<VNode>);
    const reducer$ = xs.merge(todoListSinks.onion);
    return {
        DOM: vdom$,
        onion: reducer$
    };
}